import csv
import json
from django.core.management.base import BaseCommand
from report.models import BodyType
from pathlib import Path

class Command(BaseCommand):
    help = '初始化体质数据信息'

    def handle(self, *args, **options):
        base_dir = Path(__file__).resolve().parent.parent.parent.parent
        csv_path = base_dir / 'body_type.csv'

        with open(csv_path, 'r', encoding='utf-8') as f:
            _reader = csv.DictReader(f)
            for row in _reader:
                info = {
                    "body_type": row.get('body_type'),
                    "analysis": json.dumps( row.get('analysis'), ensure_ascii=False),
                    "symptoms": json.dumps( row.get('symptoms'), ensure_ascii=False),
                    "risk": json.dumps( row.get('risk'), ensure_ascii=False),
                    "diet": json.dumps( row.get('diet'), ensure_ascii=False),
                    "acupoint": json.dumps( row.get('acupoint'), ensure_ascii=False),
                    "acupoint_images": json.dumps( row.get('acupoint_images'), ensure_ascii=False),
                }
                body_obj = BodyType.objects.create(**info)
                self.stdout.write(self.style.SUCCESS(f'CREATE BODY_TYPE: {row.get("body_type")}'))